package net.xxcxcxcx.xc_enhancedmob.skills.basics.individual.rare;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.nbt.NbtCompound;
import net.xxcxcxcx.xc_enhancedmob.config.skill.SkillConfig;
import net.xxcxcxcx.xc_enhancedmob.damgesource.SkillDamageSource;
import net.xxcxcxcx.xc_enhancedmob.skills.BaseSkill;
import net.xxcxcxcx.xc_enhancedmob.skills.Ref;
import net.xxcxcxcx.xc_enhancedmob.skills.SkillRarity;

import java.util.Random;

public class EavdeSkill extends BaseSkill {
    public EavdeSkill(int level) {
        super(level);
    }

    public EavdeSkill(NbtCompound nbtCompound) {
        super(nbtCompound);
    }

    public EavdeSkill() {
    }

    @Override
    public SkillConfig getDefaultConfig() {
        SkillConfig skillConfig = super.getDefaultConfig();
        skillConfig.setMaxlevel(10);
        skillConfig.setMessage(getConfigMessage(skillConfig));
        return skillConfig;
    }

    @Override
    public String getConfigMessage(SkillConfig skillConfig) {
        if (skillConfig == null) return super.getConfigMessage(null);
        return String.format("闪避技能，每次受到攻击有（技能等级*6.6%%）闪避本次伤害。");
    }

    public SkillRarity getSkillRarity() {
        return SkillRarity.Rare;
    }

    @Override
    public boolean onDamaged(LivingEntity attacker, MobEntity target, DamageSource source, Ref<Float> amount, boolean ismob, boolean remote) {
        if (source instanceof SkillDamageSource source1 && source1.getPassSkill()) return true;
        Random random = new Random();
        int num = random.nextInt(100);
        if (num < getSkillLevel() * 6.6F) {
            amount.setValue(0F);
            return false;
        }
        return true;
    }
}
